import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.Date;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFDataFormat;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;


public class Program {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		TestWriteToFile wr = new TestWriteToFile();
		int p = 0;
			FileOutputStream fileOut = new FileOutputStream("filewrite.xls");
			HSSFWorkbook workbook = new HSSFWorkbook();
			HSSFSheet worksheet = workbook.createSheet("POI Worksheet");
			HSSFRow row1 = worksheet.createRow((short) p);
			p++;
	/*		HSSFCell cellA1 = row1.createCell((short) 0);
			cellA1.setCellValue("size");
			HSSFCell cellB1 = row1.createCell((short) 1);
			cellB1.setCellValue("IO");

			HSSFCell cellC1 = row1.createCell((short) 2);
			cellC1.setCellValue("NIO");
			*/
			for (int i=1;i<120;i=i+2)
			{
				HSSFRow row = worksheet.createRow(p);
				p++;
				long t1 = wr.writeIo(i*1000000, 4);
				long t2 = wr.writeNio(i*1000000, 4);
				HSSFCell cell1 = row.createCell(0);
				cell1.setCellValue(i);
				HSSFCell cell2 = row.createCell(1);
				cell2.setCellValue(t1);
				HSSFCell cell3 = row.createCell(2);
				cell3.setCellValue(t2);
				HSSFCell cell4 = row.createCell(3);
				cell4.setCellValue((t1-t2)*100/(double)t1);
			} 
			workbook.write(fileOut);
			fileOut.flush();
			fileOut.close();
		 p=0;
		FileOutputStream file = new FileOutputStream("memory.xls");
		HSSFWorkbook book = new HSSFWorkbook();
		HSSFSheet sheet = book.createSheet("POI Worksheet");
		HSSFRow rowf = sheet.createRow((short) p);
		p++;
		HSSFCell c1 = rowf.createCell((short) 0);
		c1.setCellValue("size");
		HSSFCell c2 = rowf.createCell((short) 1);
		c2.setCellValue("IO");
		HSSFCell c3 = rowf.createCell((short) 2);
		c3.setCellValue("NIO");
		HSSFCell c4 = rowf.createCell((short) 3);
		c4.setCellValue("Memory");
		HSSFCell c5 = rowf.createCell((short) 4);
		c5.setCellValue("Loop");
		TestMemoryCopy mem = new TestMemoryCopy();
		for (int i=1;i<80;i=i+2)
			{
			HSSFRow row = sheet.createRow(p);
			p++;
				long t1 = mem.testIo(i*1000000,4);
				long t2 = mem.testNio(i*1000000, 4);
				long t3 = mem.testSystem(i*1000000, 4);
				long t4 = mem.testDummy(i*1000000, 4);
				HSSFCell cel1 = row.createCell(0);
				cel1.setCellValue(i);
				HSSFCell cel2 = row.createCell(1);
				cel2.setCellValue(t1);
				HSSFCell cel3 = row.createCell(2);
				cel3.setCellValue(t2);
				HSSFCell cel4 = row.createCell(3);
				cel4.setCellValue(t3);
				HSSFCell cel5 = row.createCell(4);
				cel5.setCellValue(t4);
	}
		book.write(file);
		file.flush();
		file.close();
	}
	
	
}


